# -*- coding: utf-8 -*-
#
# Currency Converter Copyright (C) 2009  Chris Marsh
#
# Currency Converter is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.
#
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# *********************************************************************************
#
# rates_table.py, This module represents the gui of the conversion rates table.
#
# *********************************************************************************

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QTableWidget,  QTableView,  QAbstractItemView
from converter import ConversionType

# *********************************************************************************

class RatesTable(QTableWidget):
    """
        Result Table for Currency Converter.
        Creates 7 columns and maintains a fixed width for the columns.
    """
    def __init__(self, parent = None):
        super(RatesTable, self).__init__(parent)
    
        #TODO: Make the viewable units selectable from options
        self.idList = [
                       ['', 'USD',  'EUR',  'GBP',  'JPY',  'CAD',  'AUD'], 
                       ['', 'mm',  'cm',  'm', 'Fth', 'ft',  'yd'], 
                       ['', 'n',  'kg',  'oz', 'pd', 'qt', 'st']
                       ]
        self.setColumnCount(7)
        self.setHeader(ConversionType.Currency)
        self.setSelectionBehavior(QTableView.SelectRows)
        self.verticalHeader().hide()
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
        rowHeight = self.fontMetrics().height() * 1.25
        self.verticalHeader().setDefaultSectionSize(rowHeight)   
    
    def setHeader(self,  type):
        self.setHorizontalHeaderLabels(self.idList[type])

    def resizeEvent(self, event):
        width = event.size().width()
        self.setColumnWidth(0, width*0.16) 
        self.setColumnWidth(1, width*0.14)
        self.setColumnWidth(2, width*0.14)
        self.setColumnWidth(3, width*0.14)
        self.setColumnWidth(4, width*0.14)
        self.setColumnWidth(5, width*0.14)
        self.setColumnWidth(6, width*0.14)

# *********************************************************************************
